import request from '@/utils/request'

// 创建订单
export function createOrder(data) {
  return request({
    url: '/order/create',
    method: 'post',
    data
  })
}

// 获取订单列表
export function getOrderList(params) {
  const status = params.status;
  delete params.status;
  
  return request({
    url: '/order/page',
    method: 'post',
    params: { status },
    data: params
  })
}

// 获取订单详情
export function getOrderDetail(id) {
  return request({
    url: `/order/${id}`,
    method: 'get'
  })
}

// 取消订单
export function cancelOrder(id) {
  return request({
    url: `/order/cancel/${id}`,
    method: 'put'
  })
}

// 送水员接单
export function acceptOrder(id) {
  return request({
    url: `/order/take/${id}`,
    method: 'put'
  })
}

// 送水员开始配送
export function deliverOrder(id) {
  return request({
    url: `/order/deliver/${id}`,
    method: 'put'
  })
}

// 送水员完成送水
export function completeOrder(id) {
  return request({
    url: `/order/complete/${id}`,
    method: 'put'
  })
}

// 更新订单状态
export function updateOrderStatus(id, status) {
  return request({
    url: `/order/updateStatus/${id}`,
    method: 'put',
    params: { status }
  })
}

// 删除订单
export function deleteOrder(id) {
  return request({
    url: `/order/delete/${id}`,
    method: 'post'
  })
}

// 导出订单数据
export function exportOrders(params) {
  return request({
    url: '/order/export',
    method: 'get',
    params,
    responseType: 'blob',
    timeout: 60000 // 增加超时时间到60秒
  })
}

// 获取订单统计数据
export function getOrderStats() {
  return request({
    url: '/statistics',
    method: 'get'
  })
} 